<template>
  <div class="container">
    <div class="header">
      <span>护士巡查打卡报表</span>
      <div class="report-type">
        <el-button type="primary" plain v-if="!isMonthly">周报</el-button>
        <el-button type="primary" plain v-else>月报</el-button>
        <el-button type="primary" plain @click="isMonthly =!isMonthly">
          {{ isMonthly? '周报' : '月报' }}
        </el-button>
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :editable-date-strings="false"
          style="margin-left: 10px"
        ></el-date-picker>
      </div>
    </div>
    <div id="chartContainer" style="width: 100%; height: 500px"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';

const isMonthly = ref(false);
const dateRange = ref([
  '2019-08-11',
  '2019-08-17'
]);

const nurses = [
  '胡素敏', '李晓晓', '刘菲敏', '王豫', '谢依夜', '蒋媛', '周丽芬', '朱傅倩', '唐妃'
];
const totalTasks = [60, 80, 75, 74, 88, 82, 80, 90, 92];
const actualChecks = [56, 78, 58, 72, 85, 82, 79, 82, 86];
const punctualityRates = [90, 95, 98, 99, 94, 99, 92, 93, 89];

onMounted(() => {
  const chart = echarts.init(document.getElementById('chartContainer'));
  const option = {
    title: {
      text: '护士巡查打卡报表',
      left: 'left'
    },
    legend: {
      data: ['总巡查任务数（次）', '实际打卡数（次）', '准点率（%）']
    },
    xAxis: {
      data: nurses
    },
    yAxis: {},
    series: [
      {
        name: '总巡查任务数（次）',
        type: 'bar',
        data: totalTasks
      },
      {
        name: '实际打卡数（次）',
        type: 'bar',
        data: actualChecks
      },
      {
        name: '准点率（%）',
        type: 'bar',
        data: punctualityRates
      }
    ]
  };
  chart.setOption(option);
});
</script>

<style scoped>
.container {
  padding: 20px;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.report-type {
  display: flex;
  align-items: center;
}
</style>